package com.ruoyi.scan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.scan.domain.Scan;
import com.ruoyi.scan.service.IScanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 浏览历史信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/scan/scan")
public class ScanController extends BaseController
{
    @Autowired
    private IScanService scanService;

    /**
     * 查询浏览历史信息列表
     */
    @PreAuthorize("@ss.hasPermi('scan:scan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Scan scan)
    {
        startPage();
        List<Scan> list = scanService.selectScanList(scan);
        return getDataTable(list);
    }

    /**
     * 导出浏览历史信息列表
     */
    @PreAuthorize("@ss.hasPermi('scan:scan:export')")
    @Log(title = "浏览历史信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Scan scan)
    {
        List<Scan> list = scanService.selectScanList(scan);
        ExcelUtil<Scan> util = new ExcelUtil<Scan>(Scan.class);
        util.exportExcel(response, list, "浏览历史信息数据");
    }

    /**
     * 获取浏览历史信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('scan:scan:query')")
    @GetMapping(value = "/{scanid}")
    public AjaxResult getInfo(@PathVariable("scanid") Long scanid)
    {
        return AjaxResult.success(scanService.selectScanByScanid(scanid));
    }

    /**
     * 新增浏览历史信息
     */
    @PreAuthorize("@ss.hasPermi('scan:scan:add')")
    @Log(title = "浏览历史信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Scan scan)
    {
        return toAjax(scanService.insertScan(scan));
    }

    /**
     * 修改浏览历史信息
     */
    @PreAuthorize("@ss.hasPermi('scan:scan:edit')")
    @Log(title = "浏览历史信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Scan scan)
    {
        return toAjax(scanService.updateScan(scan));
    }

    /**
     * 删除浏览历史信息
     */
    @PreAuthorize("@ss.hasPermi('scan:scan:remove')")
    @Log(title = "浏览历史信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scanids}")
    public AjaxResult remove(@PathVariable Long[] scanids)
    {
        return toAjax(scanService.deleteScanByScanids(scanids));
    }
}
